package com.css.openapi.controller;

import com.css.common.core.constant.ApiAccess;
import com.css.common.core.constant.AppCons;
import com.css.common.core.constant.Result;
import com.css.common.core.constant.ValidGroup;
import com.css.common.core.enums.PayKpEnum;
import com.css.openapi.BO.*;
import com.css.openapi.BO.fxdw.*;
import com.css.openapi.service.FxdwService;
import com.css.openapi.service.ZfjkpFxkpDdxxbService;
import com.css.openapi.service.ZfjkpFxkpInvoiceService;
import com.css.openapi.service.ZfjkpFxkpTssqService;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * 反向对外能力接口
 *
 * @module: 反向对外能力接口
 * @Title: JyfwController
 * @Author xlw
 * @Package com.invoice.tcc.controller
 * @Date 2024/11/19 14:18
 */
@Api(tags = "交易服务Api")
@RestController
@RequestMapping("/fxkp")
public class JyfwController {

    @Resource
    private ZfjkpFxkpInvoiceService invoiceService;

    @Resource
    private ZfjkpFxkpTssqService tssqService;

    @Resource
    private ZfjkpFxkpDdxxbService ddxxbService;

    @Resource
    private FxdwService fxdwService;


    /**
     * 创建订单
     *
     * @param fxkpOrderBO FXKP 订单 bo
     * @return {@link Result }<{@link FxkpOrderResultBO }>
     */
    @PostMapping("createOrder")
    @ApiAccess
    public Result<FxkpOrderResultBO> createOrder(@Validated(ValidGroup.COMMON.class) @RequestBody FxkpOrderBO fxkpOrderBO) {
        return Result.ok(ddxxbService.createOrder(fxkpOrderBO));
    }

    /**
     * 批量创建待支付开票订单
     *
     * @param pc FXKP 批次 bo
     * @return {@link Result }<{@link FxkpOrderResultBO }>
     */
    @PostMapping("batchCreateOrder")
    @ApiAccess
    public Result<Map<String, String>> createFxOrderBatch(@Validated @RequestBody PcBO pc) {
        pc.setSystemPay(AppCons.SYSTEM_PAY);
        return Result.ok(ddxxbService.createFxOrderBatch(pc));
    }

    /**
     * 创建待开票订单（非银联代付模式-定制化）
     * @param fxkpOrderBO FXKP 订单 bo
     * @return {@link Result }<{@link FxkpOrderResultBO }>
     */
    @PostMapping("mtCreateOrder")
    @ApiAccess
    public Result<FxkpOrderResultBO> mtCreateOrder(@Validated(ValidGroup.MAOTAI.class) @RequestBody FxkpOrderBO fxkpOrderBO) {
        return Result.ok(ddxxbService.mtCreateOrder(fxkpOrderBO));
    }

    /**
     * 确认支付开票（银联代付模式）
     *
     * @param payAndKpSubmitBO 支付和技能输出 提交 bo
     * @return {@link Result }<{@link Boolean }>
     */
    @PostMapping("payAndKpSubmit")
    @ApiAccess
    private Result<Boolean> payAndKpSubmit(@Valid @RequestBody PayAndKpSubmitBO payAndKpSubmitBO) {
        return Result.ok(ddxxbService.payAndKpSubmit(payAndKpSubmitBO));
    }

    /**
     * 创建缴税二维码（再生资源回收适用）
     *
     * @param param 参数
     * @return {@link Result }<{@link TaxQrCodeBO }>
     */
    @PostMapping("taxQrCode")
    @ApiAccess
    public Result<TaxQrCodeBO> taxQrCode(@Valid @RequestBody FxOrderQueryBO param) {
        return Result.ok(ddxxbService.taxQrCode(param));
    }

    /**
     * 订单状态查询
     *
     * @param req FX 订单状态 bo
     * @return {@link Result }<{@link FxOrderStatusResultBO }>
     */
    @PostMapping("/orderStatus")
    @ApiAccess
    public Result<FxOrderStatusVO> fxOrderStatus(@Valid @RequestBody FxOrderStatusReq req) {
        return Result.ok(ddxxbService.fxOrderStatus(req));
    }

    /**
     * 批量创建订单处理结果查询
     *
     * @return {@link Result }<{@link Object }>
     */
    @PostMapping("orderStatusBatch")
    @ApiAccess
    public Result<PcOrderStatusBO> orderStatusBatch(@Valid @RequestBody PcOrderQueryBO param) {
        return Result.ok(ddxxbService.orderStatusBatch(param));
    }

    /**
     * 订单取消
     *
     * @param fxOrderCancelBO FX 订单 CANCEL BO
     * @return {@link Result }<{@link Boolean }>
     */
    @PostMapping("orderCancel")
    @ApiAccess
    public Result<Boolean> orderCancel(@Valid @RequestBody FxOrderCancelBO fxOrderCancelBO) {
        return Result.ok(ddxxbService.orderCancel(fxOrderCancelBO));
    }

    /**
     * 获取发票
     *
     * @return {@link Result }<{@link FxOrderInvoiceBO }>
     */
    @PostMapping("queryOrderInvoice")
    @ApiAccess
    public Result<FxOrderInvoiceBO> queryOrderInvoice(@Valid @RequestBody FxOrderQueryBO fxOrderQueryBO) {
        return Result.ok(invoiceService.fxQueryOrderInvoice(fxOrderQueryBO));
    }

    /**
     * 作废红冲
     *
     * @return {@link Result }<{@link FxOrderInvoiceBO }>
     */
    @PostMapping("orderRed")
    @ApiAccess
    public Result<Boolean> orderRed(@Valid @RequestBody FxOrderQueryBO fxOrderQueryBO) {
        return Result.ok(invoiceService.orderRed(fxOrderQueryBO));
    }

    /**
     * 退税申请
     *
     * @return {@link Result }<{@link TssqBO }>
     */
    @PostMapping("returnTax")
    @ApiAccess
    public Result<TssqBO> refundTaxCommit(@Valid @RequestBody TssqParamsBO params) {
        return Result.ok(tssqService.refundTaxCommit(params));
    }

    /**
     * 退税查询
     *
     * @return {@link Result }<{@link TsjgBO }>
     */
    @PostMapping("returntTaxResult")
    @ApiAccess
    public Result<TsjgBO> refundTaxResult(@Valid @RequestBody TsjgParamsBO params) {
        return Result.ok(tssqService.refundTaxResult(params));
    }

    /**
     * 农产品订单审核
     *
     * @param params 参数
     * @return {@link Result }<{@link Boolean }>
     */
    @ApiAccess
    @PostMapping("ncpOrderAudit")
    public Result<Boolean> ncpOrderAudit(@Valid @RequestBody NcpOrderAuditBO params) {
        return Result.ok(fxdwService.ncpOrderAudit(params,  true));
    }

    /**
     * 创建废品收购二次支付订单
     *
     * @return {@link Result }<>
     */
    @ApiAccess
    @PostMapping("createZszyOrder")
    public Result<FxkpZszyOrderBO> createZszyOrder(@Validated(ValidGroup.FPSG.class) @RequestBody FxkpOrderBO fxkpOrderBO) {
        fxkpOrderBO.setZfkpqrfs(PayKpEnum.CONFIRM_PAY_AUTO_KP.getDm());
        return Result.ok(fxdwService.createZszyOrder(fxkpOrderBO));
    }

    /**
     * 查询再生资源订单状态
     *
     * @param req 要求
     * @return {@link Result }<{@link ZszyOrderStatusBO }>
     */
    @ApiAccess
    @PostMapping("queryZszyOrderStatus")
    public Result<ZszyOrderStatusBO> queryZszyOrderStatus(@Valid @RequestBody FxOrderStatusReq req) {
        return Result.ok(fxdwService.queryZszyOrderStatus(req));
    }

    /**
     * 再生资源多次支付
     *
     * @param params 参数
     * @return {@link Result }<{@link Boolean }>
     */
    @ApiAccess
    @PostMapping("zszyOrderPay")
    public Result<ZszyOrderPayResponseBO> zszyOrderPay(@Validated @RequestBody ZszyPayBO params) {
        return Result.ok(fxdwService.zszyOrderPay(params));
    }

    /**
     * 代付回单凭证下载
     *
     * @param params 参数
     */
    @ApiAccess
    @PostMapping("downloadelecreceipt")
    public Result<Map<String,Object>> downloadelecreceipt(@Validated @RequestBody DownloadElecreceiptBO params) {
        return Result.ok(fxdwService.downloadelecreceipt(params));
    }
}
